<!DOCTYPE html>
<html lang="en">
<head>
    {include file="common/new_meta" /}
</head>
<body>
    {if $Think.config.webSwitches.joinmeeting_header}
        {include file="common/new_header" /}
    {/if}

<div class="main-content">
    <div class="main-content-inner large-bottom">
        <div class="join-form">
            <div class="page-header">
                <h2 class="page-header-heading">输入您的姓名以进入</h2>
            </div>
            <div class="form-container">
                <form action="" method="post" id="joingo-form">
                    <div class="error-return-message">Error message.</div>
                    <input type="hidden" name="meeting_id" value="{$meeting_id}" />
                    <input type="hidden" name="type" value="go" />
                    <div class="form-group">
                        <input type="text" name="nickname" id="nickname" maxlength="50" class="form-control" value="{$displayName}" placeholder="请输入您的姓名">
                        <span class="error-message"></span>
                    </div>
                    <!-- <div class="form-group">
                        <input type="text" name="password" id="password" maxlength="30" class="form-control" placeholder="请输入会议密码">
                        <span class="error-message"></span>
                    </div> -->
                    <button class="btn-primary" type="submit">加入</button>
                </form>
            </div>
        </div>
    </div>
</div>

    {if $Think.config.webSwitches.joinmeeting_footer}
    {include file="common/new_footer" /}
    {/if}

<script>
    /* 加入会议 - start */
    var nicknameTouched = false;

    $('#nickname').focus(function(e) {
        if ($(this).parent('.form-group').hasClass('has-error')) {
            clearError('nickname');
        }

        nicknameTouched = true;
    })
    $('#nickname').blur(function(e) {
        if (nicknameTouched) {
            validateNickname();
        }
    });

    $('#joingo-form').on('submit', function(e) {
        e.preventDefault();

        if (validateNickname()) {
            $("#btn-primary").attr("disabled", "disabled");

            var index = layer.load(0, {
                shade: false
            }); //0代表加载的风格，支持0-2

            errorReturn("");

            var meetingId = $("#meeting-id").val();

            $.ajax({
                url:'/admin/conference/joinmeeting',
                data:$('form').serialize(),
                type:'post',
                success:function(data){
                    layer.close(index);
                    $("#btn-primary").removeAttr("disabled");
                    if (data['code']==1) {
                        // window.location.href=data['url'];
                        var lang = "{$config['language']}";
                        lang = lang.replace("zh-cn", "zh-CN");
                        lang = lang.replace("zh-tw", "zh-TW");
                        lang = lang.replace("en", "en-US");
                        lang = lang.replace("ja-jp", "ja");
                        lang = lang.replace("ko-kr", "ko");
                        window.open(data['url']+'&lang='+lang);
                    }else{
                        errorReturn(data['msg'] + '... <a href="/admin/conference/joinmeeting" style="text-decoration: underline;color: #227bff;">请重试</a>');
                    }
                }
            });

            return false;
        }

        return false;
    });

    function validateNickname() {
        clearError('nickname');

        var nickname = $('#nickname').val();
        var errorMessage = '';

        if (nickname.trim() === '') {
            errorMessage = "请输入您的姓名";
        }

        if (errorMessage) {
            showError('nickname', errorMessage);
            return false;
        } else {
            return true;
        }
    }

    function showError(inputIdName, errorMessage) {
        var inputElement = $('#' + inputIdName);
        if (inputElement.length) {
            inputElement.next('.error-message').text(errorMessage);
            inputElement.parent('.form-group').addClass('has-error');
        }
    }

    function clearError(inputIdName) {
        var inputElement = $('#' + inputIdName);
        if (inputElement.length) {
            inputElement.next('.error-message').empty();
            inputElement.parent('.form-group').removeClass('has-error');
        }
    }

    /* 加入会议 - end */

    function errorReturn(msg) {
        if (msg == '') {
            $(".error-return-message").html("");
            $(".error-return-message").hide();
        }else{
            $(".error-return-message").html(msg);
            $(".error-return-message").show();
        }
    }
</script>
</body>
</html>